package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.CustomerReturnList;
import com.atguigu.jxc.entity.CustomerReturnListGoods;
import com.atguigu.jxc.entity.PurchaseVO2;
import com.atguigu.jxc.service.CustomerReturnListGoodsService;
import com.atguigu.jxc.service.CustomerReturnListService;
import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author WZhaokang
 * @date 2020/12/30 2:09
 */
@RestController
@RequestMapping("/customerReturnListGoods")
public class CustomerReturnListController {

    @Autowired
    private CustomerReturnListService customerReturnListService;
    @Autowired
    private CustomerReturnListGoodsService customerReturnListGoodsService;


    //请求URL：http://localhost:8080/customerReturnListGoods/save?returnNumber=XT1605772786495（退货单号）
    @RequestMapping("/save")
    public ServiceVO save(CustomerReturnList customerReturnList, String customerReturnListGoodsStr, HttpSession session){
        customerReturnListService.save(customerReturnList,customerReturnListGoodsStr,session);
        return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS,null);
    }

    //请求URL：http://localhost:8080/customerReturnListGoods/list
    @RequestMapping("/list")
    public Map<String,List<CustomerReturnList>> list(String returnNumber, Integer customerId, Integer state, String sTime,String eTime){
        //
        Map map = new HashMap();
        List<CustomerReturnList> customerReturnLists = customerReturnListService.list(returnNumber,customerId,state,sTime,eTime);
        map.put("rows",customerReturnLists);
        return map;
    }


    //请求URL：http://localhost:8080/customerReturnListGoods/goodsList
    @RequestMapping("/goodsList")
    public Map<String, List<CustomerReturnListGoods>> goodList(Integer customerReturnListId){
        Map map = new HashMap();
        List<CustomerReturnListGoods> customerReturnListGoodsList = customerReturnListGoodsService.goodList(customerReturnListId);
        map.put("rows",customerReturnListGoodsList);
        return map;
    }

    //请求URL：http://localhost:8080/customerReturnListGoods/delete
    @RequestMapping("/delete")
    public ServiceVO delete(Integer customerReturnListId){
        customerReturnListService.delete(customerReturnListId);
        return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS,null);
    }

    //请求URL：http://localhost:8080/customerReturnListGoods/count
    @RequestMapping("/count")
    public String count(String sTime, String eTime, Integer goodsTypeId, String codeOrName){
        List<PurchaseVO2> serviceVOList = customerReturnListService.count(sTime,eTime,goodsTypeId,codeOrName);
        Gson gson = new Gson();
        String json = gson.toJson(serviceVOList);
        return json;
    }
}
